<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: aquamarine;
            transition: 1s linear;
            transform: translateX(0px);
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <button>点击</button>
    <script>
        document.querySelector('button').addEventListener('click', function () {
            animate('.box', {
                transform: 'translateX(500px)',
                width: '200px',
            }, () => {
                console.log('hello world');
            })
        })
        function animate(selector, cssObj, callback) {
            const box = document.querySelector(selector);
            box.setAttribute('style',Object.keys(cssObj).map(key => `${key}: ${cssObj[key]};`).join(''));
            setTimeout(() => {
                callback && callback();
            },1000)
        }
    </script>
</body>
</html>